<%@ page language="java" pageEncoding="UTF-8"
	errorPage="../../defaultException.jsp"%>
<%@include file="../../tags.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>勾选首页展示目的地信息</title>
<%@include file="../../head.jsp"%>
</head>
<body>
	<table class="fitem"  style="width: 600px">
		<tr style="width: 600px">
			<td width="300px">名称:
			</td>
			<td width="200px"><input id="destId" type="text" />
			</td>
			<td align="right" width="100px"><button id="sub" value="查询"
					onclick="searchForm()">查询</button></td>
		</tr>
	</table>
		<table id="list_data_title">

			<thead>
				<tr>
					<th data-options="field:'link',formatter:formatCell">是否勾选</th>
					<th data-options="field:'linkId',width:100">勾选项Id</th>
					<th data-options="field:'title',width:100">勾选项名称</th>
					<th data-options="field:'source',formatter:formatMiniCell,width:200">特色项图片</th>
				</tr>
			</thead>
		</table>

<script type="text/javascript">
function formatCell(value,row,index){
	   if (value == 1){
		   return "<input name='link' checked='checked' type='checkbox'/>";
	   }
	   else{
		   return "<input name='link' type='checkbox'/>";
	   }
}
function formatMiniCell(value, row, index) {
	return "<img src='${image_domain}"+value+row.small+"' width='150' height='100'>";
}
function searchForm() {
	var tempName = $('#destId').attr("value");

	$('#list_data_title').datagrid('load', {
		tempName : tempName
	});
}
$('#list_data_title').datagrid({ 
    title:'要勾选信息', 
    iconCls:'icon-edit',//图标 
    width: 750, 
    height: 450, 
    nowrap: false, 
    striped: true, 
    border: true, 
    collapsible:false,//是否可折叠的 
    fit:false,
    remoteSort:false,  
    onLoadSuccess:function(data){
    	$(":checkbox[name='link']").each(function(index){
    		$(this).attr('index',index);
			$(this).click(function(){
				var index = $(this).attr('index');
				var rows = $('#list_data_title').datagrid('getData').rows;
				var check = $(this).attr('checked');
				var row = rows[index];
				if(check=='checked'){
					row['checkInfo'] = 'add';
				}

				var saveAction = "${cpath}/admin/home/category/item/save?categoryId=${categoryId}";
				$.post(saveAction, row, function(result) {
					if (result.resultCode === '00000000') {
						$('#list_data_title').datagrid('reload'); // reload the user data
						$.messager.alert("提示", result.resultMsg, "info");
					} else {
						$.messager.alert("错误", result.resultMsg, "error");
					}
				}, 'json');
			});
		});
    },
    url:'${cpath}/admin/home/category/item/add/list?featureCategoryId=${featureCategoryId}',
    singleSelect:false,//是否单选 
    rownumbers:true,
    pagination:true,//分页控件
    idField:'homeId'
}); 
//设置分页控件 
var p = $('#list_data_title').datagrid('getPager'); 
$(p).pagination({ 
    pageSize: 10,//每页显示的记录条数，默认为10 
    pageList: [5,10,15],//可以设置每页记录条数的列表 
    beforePageText: '第',//页数文本框前显示的汉字 
    afterPageText: '页    共 {pages} 页', 
    displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
    onBeforeRefresh:function(){
        $(this).pagination('loading');
        //alert('before refresh');
        $(this).pagination('loaded');
    }
}); 

</script>
	<style type="text/css">
#fm {
	margin: 0;
	padding: 20px 20px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 90px;
}

td {
	white-space: nowrap;
}
</style>
</body>
</html>